<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
       <template #tableSearch>
        <a-col :span="8">
          <a-form-item label="等级名称" field="name">
            <a-input v-model="searchForm.name" placeholder="请输入等级名称" allow-clear />
          </a-form-item>
          
        </a-col>
        
      </template>
      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import api from '@/api/user'

// 引用定义
const crudRef = ref()
const editRef = ref()
const optionData = reactive({})



// 搜索表单
const searchForm = ref({
  name: '',
})

// SaTable 基础配置
const options = reactive({
  api: api.getLevelList,
  rowSelection: { showCheckedAll: true },
  showTools: false,
  add: {
    show: true,
    text: '新增消费等级',
    func: async () => {
      editRef.value?.open('add')
    },
  },
  edit: {
    show: true,
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
  delete: {
    show: false,
  },
})

// SaTable 列配置
const columns = reactive([
  { title: 'ID', dataIndex: 'id', width: 50 },
  { title: '等级名称', dataIndex: 'name', width: 100 },
  { title: 'Logo', dataIndex: 'logo',type:'image', width: 100 },
  { title: '升级金额', dataIndex: 'upgrade_amount', width: 100 },
  { title: '保级金额', dataIndex: 'grading_amount', width: 100 },
  { title: '多少天更新级别', dataIndex: 'days', width: 150 },
  { title: '创建时间', dataIndex: 'created_at', width: 180 },
])


// 页面数据初始化
const initPage = async () => {}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
